//package com.dr.cmdb.core.config;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.alibaba.fastjson.serializer.SerializeConfig;
//import com.dr.cmdb.core.annotation.MongoIdConvert;
//import org.bson.types.ObjectId;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
///**
// * @ProjectName: cmdb
// * @Package: com.dr.cmdb.application.config
// * @Description: 处理返回的mongoid为ObjectId的问题
// * @Author: duanrui
// * @CreateDate: 2021/3/20 16:09
// * @Version: 1.0
// * <p>
// * Copyright: Copyright (c) 2021
// */
//@ControllerAdvice
//public class MongoIdResponseBodyAdvice implements ResponseBodyAdvice<Object> {
//    @Override
//    public boolean supports(MethodParameter methodParameter, Class<? extends HttpMessageConverter<?>> aClass) {
//        //这里设置成false 它就不会再走这个类了
//        return methodParameter.getMethod().isAnnotationPresent(MongoIdConvert.class);
//    }
//
//    @Override
//    public Object beforeBodyWrite(Object o, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
//        SerializeConfig config = new SerializeConfig();
//        //解决mongo id序列化问题
//        config.put(ObjectId.class, new ObjectIdJsonSerializer());
//        return JSONObject.parse(JSON.toJSONString(o, config));
//    }
//}
